﻿using System;
using System.Collections.Generic;
using Pap.Data;

namespace Pap.Services
{
    /// <summary>
    /// 
    /// </summary>
    public interface ILoanExecutionService
    {
        /// <summary>
        /// Validates the gurantor.
        /// </summary>
        /// <param name="ssn">The SSN.</param>
        /// <returns></returns>
        bool ValidateGurantor(string ssn);

        /// <summary>
        /// Validates the gurantor warning.
        /// true if the payed limit is more than .75, false if less
        /// </summary>
        /// <param name="ssn">The SSN.</param>
        /// <returns>
        /// true if the payed limit is more than .75, false if less
        /// </returns>
        bool ValidateGurantorWarning(string ssn);

        /// <summary>
        /// Creates the loan execution.
        /// </summary>
        /// <param name="loan">The loan.</param>
        /// <param name="boardLoan">The board loan.</param>
        /// <param name="executionDate">The execution date.</param>
        /// <param name="checkNumber">The check number.</param>
        /// <param name="checkDate">The check date.</param>
        /// <param name="guarantorName">Name of the guarantor.</param>
        /// <param name="guarantorSSN">The guarantor SSN.</param>
        /// <param name="notes">The notes.</param>
        /// <param name="createInstallments">if set to <c>true</c> [create installments].</param>
        /// <returns></returns>
        ILoanExecution CreateLoanExecution(ICustomerLoan loan, IBoardLoan boardLoan, DateTime executionDate, string checkNumber, DateTime checkDate, string guarantorName, string guarantorSSN, string notes, bool createInstallments);

        /// <summary>
        /// Updates the loan execution.
        /// </summary>
        /// <param name="loanExecution">The loan execution.</param>
        /// <param name="loan">The loan.</param>
        /// <param name="boardLoan">The board loan.</param>
        /// <param name="executionDate">The execution date.</param>
        /// <param name="checkNumber">The check number.</param>
        /// <param name="checkDate">The check date.</param>
        /// <param name="guarantorName">Name of the guarantor.</param>
        /// <param name="guarantorSSN">The guarantor SSN.</param>
        /// <param name="note">The note.</param>
        /// <returns></returns>
        bool UpdateLoanExecution(ILoanExecution loanExecution, ICustomerLoan loan, IBoardLoan boardLoan, DateTime executionDate, string checkNumber, DateTime checkDate, string guarantorName, string guarantorSSN, string note);

        /// <summary>
        /// Creates the loan execution installments.
        /// </summary>
        /// <param name="loanExecution">The loan execution.</param>
        /// <returns></returns>
        IEnumerable<ILoanExecutionInstallment> CreateLoanExecutionInstallments(ILoanExecution loanExecution);

        /// <summary>
        /// Calculates the penalities.
        /// </summary>
        void CalculatePenalities();

        /// <summary>
        /// Gets all excuation dues.
        /// </summary>
        /// <param name="exceutionID">The exceution ID.</param>
        /// <returns></returns>
        double GetAllExcuationDues(Guid exceutionID);

        /// <summary>
        /// Gets all excuation amount.
        /// </summary>
        /// <param name="exceutionID">The exceution ID.</param>
        /// <returns></returns>
        double GetAllExcuationAmount(Guid exceutionID);

        /// <summary>
        /// Gets the installment payment amount.
        /// </summary>
        /// <param name="loanInstallmentID">The loan installment ID.</param>
        /// <returns></returns>
        double GetInstallmentPaymentAmount(Guid loanInstallmentID);

        ///// <summary>
        ///// Pays for execution.
        ///// </summary>
        ///// <param name="executionID">The execution ID.</param>
        ///// <param name="paymentAmount">The payment amount.</param>
        ///// <param name="ReceipteNumber">The receipte number.</param>
        ///// <param name="paymentDate">The payment date.</param>
        ///// <returns>
        ///// returns true if all execution's installments are paied
        ///// </returns>
        bool PayForExecution(Guid executionID, double paymentAmount, long ReceipteNumber, DateTime paymentDate);

        IReceipt PayInstallment(Guid installment, double paymentAmount, long receiptNumber, DateTime paymentDate);

        /// <summary>
        /// Creates the loan execution.
        /// </summary>
        /// <param name="lastExecution">The last execution.</param>
        /// <param name="executionDate">The execution date.</param>
        /// <param name="paymentPeriod">The payment period.</param>
        /// <param name="loanAmount">The loan amount.</param>
        /// <returns></returns>
        ILoanExecution CreateLoanExecution(ILoanExecution lastExecution, DateTime executionDate, int paymentPeriod, double loanAmount);

        /// <summary>
        /// Gets the loan history.
        /// </summary>
        /// <param name="lastLoanExecution">The last loan execution.</param>
        /// <param name="closeType">Type of the close.</param>
        /// <param name="notes">The notes.</param>
        /// <returns></returns>
        ICustomerLoanHistory GetLoanHistory(ILoanExecution lastLoanExecution, LoanHistoryCloseTypes closeType, string notes);
    }
}
